var handleBlog = require("./src/router/blog/index")
var handleUser = require("./src/router/user/index")

module.exports= async (resquest,response)=>{
    //统一处理请求的返回格式
    response.setHeader('Content-Type', 'application/json');

    //处理blog 
    //如果data为undefined则代表当前请求没有被handleBlog命中！需要继续往下处理
    //如果data不为undefined则代表当前请求被handleBlog命中！ 不需要继续处理
    var result = await handleBlog(resquest,response);
    if(result !== undefined){
      if(result.data === "error"){
        response.writeHead(500,result.message);
        response.end()
    }else{
        response.end(JSON.stringify(result.data))
    }
    return
    }

    //处理用户
    var result2 = await handleUser(resquest,response);
    if(result2 !== undefined){
        if(result2.data === "error"){
            response.writeHead(500,result2.message);
            response.end()
        }else{
            response.end(JSON.stringify(result2.data))
        }
        return
    }
   
    //处理404
    response.writeHead(404,"router not found");
    response.end()
}